<?php
	
	require("./include.php");
	
	if(!$_SESSION[user_id]){
		?>
		<script>
			alert("로그인 하셔야 합니다");
			location.replace("board_login.php");
		</script>
		<?
	}
	
	if(trim($_POST[b_title]) == ""){
		?>
		<script>
			alert("글 제목을 입력하세요";
			history.back();
		</script>
		<?
		exit;
	}
	
	if(trim($_POST[b_contents]) == ""){
		?>
		<script>
			alert("글 내용을 입력하세요";
			history.back();
		</script>
		<?
		exit;
	}
	
	$sql = "insert into tb_board set b_reply = '', m_id='".$_SESSION[user_id]."', m_name='".$_SESSION[user_name]."', b_title='".addslashes(htmlspecialchars($_POST[b_title]))."', 
			b_contents='".addslashes(htmlspecialchars($_POST[b_contents]))."', b_regdate = now()";
	sql_querry($sql);
	
	$b_idx = mysql_insert_id();
	
	$sql = "update tb_board set b_num = '".$b_idx."' where b_idx = '".$b_idx."'";
	sql_querry($sql);
?>
<script>
	alert("글이 저장 되었습니다");
	location.replace("./board_list.php");
</script>